package com.mice.game.trigger{
	import com.mice.game.GameEngine;
	import com.mice.game.core.Actor;
	import com.mice.game.core.Fighter;
	import com.mice.game.core.Player;

	public class SpawnTrigger{
		private static var _instance:SpawnTrigger;
		
		public function SpawnTrigger(){}
		
		public static function get instance():SpawnTrigger{
			if (_instance == null)
				_instance = new SpawnTrigger();
			return _instance;
		}
		
		/**
		 * 通过战斗单位的metaId, level来初始化单位,并在之后用附加属性进行修正
		 * @param metaId
		 * @param level
		 * @param team
		 */		
		public function spawn(metaId:int, level:int, team:int):Fighter{
			var fighter:Fighter = new Fighter();
			fighter.initialize(metaId, level);
			//TODO
			//correctFighter(fighter);
			
			if (team == Player.TEAM_RED){
				fighter.x = 0;
				fighter.direction = 1;
				FighterTrigger.instance.addRedFighter(fighter);
				GameEngine.instance.player.useEnergy(fighter.meta.costEnergy);
			}else{
				fighter.x = 960;
				fighter.direction = -1;
				FighterTrigger.instance.addBlueFighter(fighter);
				GameEngine.instance.ai.useEnergy(fighter.meta.costEnergy);
			}
			fighter.run();
			
			return fighter;
		}
	}
}